import { httpFetch } from '../../utils/req'
import { data2292, data2293, data2294 } from './lv6/submit_data.js'
// import AES from "../cryptoPwd.js"
// POST https://api.jinkex.com/edu/v1/student/login
// data {"school_host":"haut.hnscen.cn","token":"","device":"app","num":"201983020095","password":"123456"}

// Cookie
// 	065df9c8090f46bbbceecdc880f43458=WyIyMDczMTUzMjc3Il0; 1a28e23538344d17836a8557bc6cdd84=WyIzNDA2NzQyNzEzIl0

// WyI0MDk3OTkxNTk1Il0

// enjoin WyI0MDk3OTkxNTk1Il0
// enjoin WyIyMDczMTUzMjc3Il0

// WyIyMDczMTUzMjc3Il0
// WyI0MDk3OTkxNTk1Il0

const examData = {
  data2292,
  data2293,
  data2294
}

const headers = {
  Cookie: '',
  Authorization: 'haut.hnscen.cn',
  Host: 'api.jinkex.com',
  Referer: 'https://haut.hnscen.cn/',
  Origin: 'https://haut.hnscen.cn',
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0',
  'Sec-Fetch-Dest': 'empty',
  'Sec-Fetch-Mode': 'cors',
  'Sec-Fetch-Site': 'cross-site',
  'Content-Type': 'application/json;charset=utf-8'
}

const url = 'https://api.jinkex.com/exam/v1/user/submit'

export default (query, request) => {
  return new Promise((resolve, reject) => {
    const testId = query.testid
    const token = query.token
    if (testId && token) {
      let key = `data${testId}`
      if (examData.hasOwnProperty(key)) {
        const data = examData[key]
        data.token = token
        httpFetch(
          url,
          {
            method: 'post',
            body: data,
            headers: headers
          }
        ).promise.then(res => {
          resolve(res.body)
        }).catch(e => {
          reject(e)
        })
      } else {
        reject({
          code: 404,
          name: '错误',
          message: '该考试ID信息暂未开放'
        })
      }
    } else {
      reject({
        code: 404,
        name: '错误',
        message: '考试ID或TOKEN缺失'
      })
    }
  })
}
